<?php
/**
 * Created by IntelliJ IDEA.
 * User: jimmyhsu
 * Date: 2017/5/14
 * Time: 01:41
 */
$filename = $_GET['filename'];
$out_filename = $_GET['outfile_name'];
if(!file_exists($filename)) {
    echo 'Not Found' . $filename;
    exit;
} else {
    header('Accept-Ranges: bytes');
    header('Accept-Length: ' . filesize($filename));
    header('Content-Transfer-Encoding: binary');
    header('Content-type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . $out_filename);
    header('Content-Type: application/octet-stream; name=' . $out_filename);
    if(is_file($filename) && is_readable($filename)){
        $file = fopen($filename, "r");
        echo fread($file, filesize($filename));
        fclose($file);
    }
    exit;
}